package io.lkt.modules.sys.service.impl;

import com.baomidou.mybatisplus.extension.service.IService;
import io.lkt.commons.dynamic.datasource.annotation.DataSource;
import io.lkt.modules.sys.entity.PushHeadLogEntity;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.lkt.common.utils.PageUtils;
import io.lkt.common.utils.Query;

import io.lkt.modules.sys.dao.KeywordInfoDao;
import io.lkt.modules.sys.entity.KeywordInfoEntity;
import io.lkt.modules.sys.service.KeywordInfoService;


@Service("keywordInfoService")
@DataSource("slave1")
public class KeywordInfoServiceImpl extends ServiceImpl<KeywordInfoDao, KeywordInfoEntity> implements KeywordInfoService {
    @Autowired
    KeywordInfoDao keywordInfoDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String type=params.get("keywordType").toString();
        String keywordContent=params.get("keywordContent").toString();
        IPage<KeywordInfoEntity> page = this.page(
                new Query<KeywordInfoEntity>().getPage(params),
                new QueryWrapper<KeywordInfoEntity>().eq(StringUtils.isNotBlank(type),"keyword_type", type).like(StringUtils.isNotBlank(keywordContent),"keyword_content", keywordContent)
        );

        return new PageUtils(page);
    }

    @Override
    public KeywordInfoEntity getById(Integer id) {

        return keywordInfoDao.selectById(id);
    }

    @Override
    public int insert(KeywordInfoEntity keywordInfoEntity) {
        return keywordInfoDao.insert(keywordInfoEntity);
    }

    @Override
    public int update(KeywordInfoEntity keywordInfoEntity) {
        return keywordInfoDao.updateById(keywordInfoEntity);
    }

    @Override
    public Integer totalByContent(KeywordInfoEntity keywordContent) {
        return keywordInfoDao.totalByContent(keywordContent);
    }

    @Override
    public PushHeadLogEntity getUserCount(String gzhCode, String beginDate, String endDate, Integer headId) {
        return keywordInfoDao.getUserCount(gzhCode, beginDate, endDate, headId);
    }

}
